package com.supergzt.utils;


import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;

/**
 * @author 张钧
 * @Description
 * @create 2023-03-24 14:21
 */
public class MyReflectionUtils extends ReflectionUtils {
	public static void setFieldValue(Object object, String fieldName, Object fieldValue) {
		try {
			Field field = object.getClass().getDeclaredField(fieldName);
			field.setAccessible(true);
			field.set(object, fieldValue);
		} catch (NoSuchFieldException | IllegalAccessException e) {
			throw new RuntimeException("Failed to set field value: " + fieldName, e);
		}
	}

	public static Object getFieldValue(Object object, String fieldName) {
		try {
			Field field = object.getClass().getDeclaredField(fieldName);
			field.setAccessible(true);
			return field.get(object);
		} catch (NoSuchFieldException | IllegalAccessException e) {
			throw new RuntimeException("Failed to get field value: " + fieldName, e);
		}
	}
}
